﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TienTeTuong.back_end
{
    public partial class EditArticle : System.Web.UI.Page
    {
        public List<ArticlecategoryDTO> categorys = new List<ArticlecategoryDTO>();
        public ArticlecategoryBUS ctBus = new ArticlecategoryBUS();
        public ArticleBUS artBus = new ArticleBUS();
        public ArticleDTO article = new ArticleDTO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Admin"] == null)
            {
                Response.Redirect("Default.aspx");
            }
            categorys = ctBus.GetListArticlecategory();
            string id = Request.Params["id"];
            if (Page.IsPostBack)
            {
                article = artBus.GetArticleDetailById(id);
                article.ArtCateID = artCateID.Value;
                article.Title = txtTitle.Text;
                article.ShortDescript = txtDescription.Text;
                article.Content = txtContent.Value;
                article.Active = bool.Parse(isActive.Value);
                article.Status = 1;
                article.VipLevel = 1;
                if (Session["imgArt"] != null)
                {
                    article.Image = Session["imgArt"].ToString();
                    Session["imgArt"] = null;
                }
                article.Author = txtAuthor.Text;
                article.Hot = bool.Parse(isHot.Value);
                artBus.update(article);
                Response.Redirect("Articalemanagement.aspx");
            }
            else if (!string.IsNullOrEmpty(id))
            {
                article = artBus.GetArticleDetailById(id);
                txtTitle.Text = article.Title;
                txtDescription.Text = article.ShortDescript;
               // txtVipLevel.Text = article.VipLevel.ToString();
                txtAuthor.Text = article.Author;
            }
        }
    }
}